﻿using BusinessTier;
using DataTier;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model;
using NHibernate;

namespace DataTierTest
{
    [TestClass]
    public class TagDaoShould
    {
        private TagDao _tagDao;
        private InMemoryDatabase _inMemoryDataBase;
        private ISession _session;


        [TestInitialize]
        public void Setup()
        {
            _inMemoryDataBase = new InMemoryDatabase(typeof(TagDao).Assembly);
            _session = _inMemoryDataBase.Session;
            _tagDao = new TagDao(_inMemoryDataBase.SessionProvider);
        }

        [TestCleanup]
        public void TearDown()
        {
            _inMemoryDataBase.Dispose();
        }


        [TestMethod]
        public void SaveTag()
        {
            var tagToSave = new Tag("SomeName");
            _tagDao.Save(tagToSave);
            _inMemoryDataBase.FlushAndClear();
            ITag tagToLoad = _session.CreateQuery("From Tag").UniqueResult<Tag>();
            Assert.AreEqual("SomeName", tagToLoad.Name);
        }




    }
}
